package com.jerry.huihome.module.find_near_mine.adapter;

import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jerry.huihome.R;
import com.jerry.huihome.base.BaseApplication;
import com.jerry.huihome.base.BaseViewHolder;
import com.jerry.huihome.base.MyBaseAdapter;
import com.jerry.huihome.module.find_near_mine.activity.ActivitypictoActivity;
import com.jerry.huihome.module.find_near_mine.entity.ActivityListEntity;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import butterknife.BindView;

/**
 * Created by axiang on 2016/5/12.
 */
public class ActivityListAdapter extends MyBaseAdapter{
    private final FragmentActivity activity;
    private final List<ActivityListEntity.BodyBean.ItemsBean> list;
    private final ImageLoader imageLoader;

    public ActivityListAdapter(FragmentActivity activity, List<ActivityListEntity.BodyBean.ItemsBean> itemsBeanList){
        super(activity,itemsBeanList);
        this.activity = activity;
        this.list = itemsBeanList;
        imageLoader = BaseApplication.getApplication().getImageLoader();
    }

    @Override
    public int getLayoutId(){
        return R.layout.activity_recycle_list;
    }

    @Override
    public BaseViewHolder getViewHolder(){
        return new ActivityViewHolder();
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder){
        ActivityViewHolder holder = (ActivityViewHolder) viewHolder;
        final ActivityListEntity.BodyBean.ItemsBean itembean=
                (ActivityListEntity.BodyBean.ItemsBean) getItem(viewHolder.position);
        imageLoader.displayImage(itembean.getCoverimg(),holder.image);
        holder.introduce.setText(itembean.getTheme());
        if(itembean.getApplystatus()==0){
            holder.applystate.setText("正在报名");
        }else if(itembean.getApplystatus()==1){
            holder.applystate.setText("报名已结束");
            holder.applystate.setTextColor(Color.parseColor("#FFC4321B"));
        }

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = format.format(new Date(itembean.getActEndTime()));
        holder.time.setText(date);
        holder.applyresult.setText(""+itembean.getApplyCount());
        holder.address.setText(itembean.getAddress());
        holder.image.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent intent = new Intent();
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                intent.putExtra("openUrl",itembean.getOpenUrl());
                intent.putExtra("shareUrl",itembean.getShareUrl());
                intent.setClass(activity, ActivitypictoActivity.class);
                activity.startActivity(intent);
            }
        });

    }
    public class ActivityViewHolder extends BaseViewHolder{
        @BindView(R.id.images)
        ImageView image;
        @BindView(R.id.introduce)
        TextView introduce;
        @BindView(R.id.applystate)
        TextView applystate;
        @BindView(R.id.applyresultnumber)
        TextView applyresult;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.address)
        TextView address;




    }
}
